package mysgoog.gtp;

import java.util.*;

import mysgoog.board.*;
import mysgoog.bot.*;
import mysgoog.util.*;

/**
 * Not just a game but "The Game".
 */
public class PatternTestGame extends GTP
{
    private GoBot bot;
    private Board board;

    public static void main(String args[]) throws Throwable
    {
        Game endersgame = new Game();
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextLine())
        {
            try
            {
                endersgame.parse(sc.nextLine());
            }
            catch (Throwable e)
            {
                e.printStackTrace(Lib.log);
                Lib.log.flush();
                throw e;
            }
        }
    }
    public PatternTestGame()
    {
        board = new DragonBoard(Config.getBoardSize());
        //bot = new CombinedBot();
        bot = new Bot_vs2();
        bot.setBoard(board);
    }
    @Override
    public void quit()
    {
        // XXX
        System.exit(0);
    }
    @Override
    public void clear_board()
    {
        board = new DragonBoard(Config.getBoardSize());
        bot.setBoard(board);
    }
    @Override
    public ArrayList<Vertex> fixed_handicap(int value)
    {
        // TODO
        return null;
    }
    @Override
    public ArrayList<Vertex> place_free_handicap(int value)
    {
        // TODO
        return null;
    }
    @Override
    public void set_free_handicap(ArrayList<Vertex> vertices)
    {
        // TODO
    }
    @Override
    public void play(Color color, Vertex vertex)
    {
        if (vertex.isPass())
            board.pass(color);
        else
            board.play(color, board.makePos(vertex.x, vertex.y));
    }
    /**
     * A stone of the requested color is played where the engine chooses. The
     * number of captured stones is updated if needed and the move is added to
     * the move history. <br>
     * Notice that \pass" is a valid vertex and should be returned if the engine
     * wants to pass. Use \resign" if you want to give up the game. The
     * controller is allowed to use this command for either color, regardless
     * who played the last move.
     * 
     * @param color
     *            Color for which to generate a move.
     * @return Vertex where the move was played or the string \resign".
     */
    @Override
    public Vertex genmove(Color color)
    {
        Vertex vertex = bot.genMove(color);
        play(color, vertex);
        Lib.debug("= " + vertex.toString());
        return vertex;
    }
    public void undo()
    {
        board.undo();
    }
    public String showboard()
    {
        return board.toString();
    }
}
